package com.kfit.java8.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class Test8 {
	public static void main(String[] args) {
		
		List<Integer> someNumbers = Arrays.asList(1, 2, 3, 4, 5,6);
        //找到第一个能够被3整除的数
		Optional<Integer> findFirstOptional = someNumbers.stream()
                        .filter(x -> x % 3 == 0)
                        .findFirst(); 
        //结果：3
        System.out.println(findFirstOptional.get());
        
        findFirstOptional = someNumbers.stream()
                .filter(x -> x % 3 == 0)
                .findAny(); 
		//结果：3
		System.out.println(findFirstOptional.get());
	}
	
	
}
